function [ fsi, fgi ] = diffWithBG(img_color, img_mean, img_var )
%DIFFWITHBG Summary of this function goes here
%   Detailed explanation goes here
    DIFF_THR = 0.05;
    DIFF_THR2 = 0.1;

    diff2 = imabsdiff(img_color, img_mean);
    fsi = im2bw(im2bw(diff2(:,:,1),DIFF_THR2)+im2bw(diff2(:,:,2),DIFF_THR2)+im2bw(diff2(:,:,3),DIFF_THR2),0.5); 
                     
	diff = zeros(size(img_mean,1), size(img_mean,2),1);
	helper = imsubtract(img_color, img_mean);
% 	for x = 1 : size(img_mean,1)
%         for y = 1 : size(img_mean,2)
%             sigma = [ img_var(x,y,1) 0 0;
%                       0 img_var(x,y,2) 0; 
%                       0 0 img_var(x,y,3)];
%              
%             help = [helper(x,y,1) helper(x,y,2) helper(x,y,3)]';
%         	diff(x,y) = det(sigma)^(-0.5)*exp(-0.5 * (help' / sigma) * help); 
%         end 
% 	end
%   %Threshold, which segments foreground.
% 	diff = diff .* (2.0*pi)^(-0.5);
% 	fgi = 1-im2bw(diff(:,:),DIFF_THR); 
    
    mu_RGB = mean(mean(img_mean));
    cov = var(var(img_var));
    cov = diag(cov(:)');
    y = mvnpdf(reshape(double(img_color), [], 3), mu_RGB(:)', cov);
    fgi = reshape(y, size(img_color,1), size(img_color,2));
    fgi = fgi < 0.16;

end

